package cn.shengongying.api.controller;

import cn.shengongying.anon.User;
import cn.shengongying.api.dto.InformationInDTO;
import cn.shengongying.bean.BaseUser;
import cn.shengongying.bean.ResponseResult;
import cn.shengongying.model.Information;
import cn.shengongying.service.IInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * author: RXK
 * date: 2022/1/18 星期二
 * desc:
 */
@Api(value = "消息")
@RestController
@RequestMapping("/boss/information")
public class InformationController extends BaseController {

    private final IInformationService informationService;

    public InformationController(IInformationService informationService) {
        this.informationService = informationService;
    }

    @ApiOperation(value = "消息统计")
    @PostMapping("/statistic")
    public ResponseResult<Map<Integer,Integer>> informationStatistic(@ApiIgnore @User BaseUser baseUser) {
        Map<Integer,Integer> count = informationService.statistic(baseUser.getId());
        return ResponseResult.success(count);
    }

    @ApiOperation(value = "列表")
    @PostMapping("/list")
    public ResponseResult<List<Information>> list(@ApiIgnore @User BaseUser baseUser, @RequestBody InformationInDTO inDTO) {
        List<Information> informationList = informationService.findByUserIdAndType(baseUser.getId(), inDTO.getType(),inDTO.offset(),inDTO.getPageSize());
        return ResponseResult.success(informationList);
    }

}
